<%-- 
    Document   : CMS_member
    Created on : Dec 1, 2013, 3:34:22 AM
    Author     : BibooChung
--%>


<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "java.util.*" import="cart.hibernate.membershipTier.*" import="cart.hibernate.member.*" import="cart.*,java.net.*,java.text.*" %>
<jsp:useBean id = "membershipTierManager" scope= "request" class = "cart.hibernate.membershipTier.ManageMembershipTier" />
<jsp:useBean id = "memberManager" scope= "request" class = "cart.hibernate.member.ManageMember" />

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Manage Member</h1>

        <!-- Table with integrated management -->
        <table border="0" style="border-color:black;margin-bottom:20px;">
                <tr>
                    <th>Member ID</th>
                    <th>Password</th>
                    <th>Email</th>
                    <th>Gender</th>
                    <th>HomePhoneNumber</th>
                    <th>CellPhoneNumber</th>
                    <th>BirthDate</th>
                    <th>JoinDate</th>
                    <th>NickName</th>
                    <th>Point</th>
                    <th>FirstName</th>
                    <th>MiddleName</th>
                    <th>LastName</th>
                    <th>MembershipTier</th>
                    <th>Orders</th>
                    <th>Update?</th>
                    <th>Delete?</th>
                </tr>
                <%
                    List memberList = memberManager.getAllMember();
                    List membershipTierList = membershipTierManager.getAllMembershipTier();
                    //List orderList = orderManager.getAllOrder();

                    Iterator iterMember = memberList.iterator();
                    Iterator iterMembershipTier = membershipTierList.iterator();

                    while (iterMember.hasNext())
                    {

                        Member member = (Member) iterMember.next();
                %>
                        <tr>
                        <table>
                            <form action="ManageMemberServlet" method="post">
                                <input type="hidden" name="loginName" value="<%= member.getLoginName() %>"> 
                                <td>
                                    <%= member.getLoginName() %>
                                </td>
                                <td>
                                    <input type="text" name="password" value="<%= member.getPassword() %>" />
                                </td>
                                <td>
                                    <input type="text" name="email" value="<%= member.getEmail() %>" />
                                </td>
                                <td>
                                    <select name="gender">
                                        <option value="male" <% if(member.getGender() == 'M') out.print("selected='selected'");%> >
                                            M
                                        </option>
                                        <option value="female" <% if(member.getGender() == 'F') out.print("selected='selected'");%> >
                                            F
                                        </option>
                                    </select>
                                </td>
                                <td>
                                    <input type="text" name="homePhoneNumber" value="<%= member.getHomePhoneNumber() %>" />
                                </td>
                                <td>
                                    <input type="text" name="cellPhoneNumber" value="<%= member.getCellPhoneNumber() %>" />
                                </td>
                                <td>
                                    <input type="date" name="birthDate" value="<%= member.getBirthDate() %>" />
                                </td>
                                <td>
                                    <input type="date" name="joinDate" value="<%= member.getJoinDate() %>" />
                                </td>
                                <td>
                                    <input type="text" name="nickName" value="<%= member.getNickName() %>" />
                                </td>
                                <td>
                                    <input type="text" name="point" value="<%= member.getPoint() %>" />
                                </td>
                                <td>
                                    <input type="text" name="firstName" value="<%= member.getFirstName() %>" />
                                </td>
                                <td>
                                    <input type="text" name="middleName" value="<%= member.getMiddleName() %>" />
                                </td>
                                <td>
                                    <input type="text" name="lastName" value="<%= member.getLastName() %>" />
                                </td>
                                <td>
                                    <select name="membershipTierId">
                                        <%
                                            while (iterMembershipTier.hasNext())
                                            {
                                                MembershipTier membershipTier = (MembershipTier) iterMembershipTier.next();

                                                if(membershipTier.getMembershipTierId() == member.getMembershipTier().getMembershipTierId())
                                                    out.print("<option value='" + membershipTier.getMembershipTierId() + "' selected='selected'>" + membershipTier.getMembershipTier() + "</option>");
                                                else
                                                    out.print("<option value='" + membershipTier.getMembershipTierId() + "'>" + membershipTier.getMembershipTier() + "</option>");
                                            }
                                            iterMembershipTier = membershipTierList.iterator();
                                        %>
                                    </select>
                                </td>
                                <td>
                                    <input type="text" name="password" value="Orders" />
                                </td>
                                <td>
                                    <input type="submit" name="submit" value="update">
                                </td>
                                <td>
                                    <input type="submit" name="submit" value="delete">
                                </td>
                            </form>
                        </table>
                        </tr>
                <%        
                    }
                %>
                    <tr>
                    <table>
                        <form action="ManageMemberServlet" method="post">
                            <td>Enter new member : </td>
                            <td><input type="text" name="loginName" id="loginName"></td>
                            <td><input type="text" name="password" ></td>
                            <td><input type="text" name="email"/>
                            <td>
                                <select name="gender">
                                    <option value="male">M</option>
                                    <option value="female">F</option>
                                </select>
                            </td>
                            <td><input type="text" name="homePhoneNumber" /></td>
                            <td><input type="text" name="cellPhoneNumber" /></td>
                            <td><input type="date" name="birthDate" /></td>
                            <td><input type="date" name="joinDate" /></td>
                            <td><input type="text" name="nickName"  /></td>
                            <td><input type="text" name="point"  /></td>
                            <td><input type="text" name="firstName"  /></td>
                            <td><input type="text" name="middleName"  /></td>
                            <td><input type="text" name="lastName" /></td>
                            <td>
                                <select name="membershipTierId">
                                    <%
                                        while (iterMembershipTier.hasNext())
                                        {
                                            MembershipTier membershipTier = (MembershipTier) iterMembershipTier.next();
                                            out.print("<option value='" + membershipTier.getMembershipTierId() + "'>" + membershipTier.getMembershipTier() + "</option>");
                                        }
                                        iterMembershipTier = membershipTierList.iterator();
                                    %>
                                </select>
                            </td>
                            <td><input type="text" name="order" /></td>
                            <td><input type="submit" name="submit" value="add"></td>
                        </form>
                    </table>
                    </tr>
        </table>
    </body>
</html>
